package com.heima.config;

import com.heima.Interceptor.DoctorInterceptor;
import com.heima.Interceptor.ResidentInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Slf4j
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
         @Autowired
         private DoctorInterceptor doctorInterceptor;
         @Autowired
         private ResidentInterceptor residentInterceptor;

        @Override
        public void addInterceptors(InterceptorRegistry registry) {
                log.info("开始注册拦截器");
                 registry.addInterceptor(doctorInterceptor)
                 .addPathPatterns("/doctor/**").addPathPatterns("/message-board/**")
                 .excludePathPatterns(
                 "/doctor/login",
                 "/doctor/register",
                 "/doctor/logout",
                    "/doctor/getCode",
                    "/doctor/loginByPhone"
                         );

                 registry.addInterceptor(residentInterceptor)
                 .addPathPatterns("/resident/**").addPathPatterns("/message-board/**")
                    .excludePathPatterns(
                    "/resident/login",
                    "/resident/register",
                    "/resident/logout",
                    "/resident/getCode",
                    "/resident/loginByPhone");

        }
}
